package com.roy.KafkaTest;

import java.util.Properties;

import org.apache.kafka.clients.producer.Producer;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.apache.kafka.clients.producer.internals.DefaultPartitioner;
import org.apache.kafka.clients.producer.KafkaProducer;

public class KafkaProducerExample2 {

	public static void main(String[] args) {
        Properties props = new Properties();
        props.put("bootstrap.servers", "127.0.0.1:9092");
        props.put("acks", "all");//消息安全级别依次为 all=-1 > 1 > 0
        props.put("retries", 0);
        props.put("batch.size", 16384);
        props.put("linger.ms", 1);
        props.put("buffer.memory", 33554432);
        props.put("client.id", "....");
        props.put("partitioner.class", DefaultPartitioner.class);
        
        
        props.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
        props.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");

        Producer<String, String> producer = new KafkaProducer<String, String>(props);
        for(int i = 0; i < 5; i++)
            producer.send(new ProducerRecord<String,String>("topic1", Integer.toString(i), Integer.toString(i)));

        producer.close();
    }
}
